package org.opens.controller;

import org.opens.aop.aspect.Token;
import org.opens.interceptor.TokenInterceptor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/idempotence")
public class ApiIdempotenceController {

    @GetMapping(value = "/")
    public String goIdempotence() {
        return "idempotence";
    }

    @GetMapping(value = "/detail")
    @Token(generate = true)
    public String goDetail(HttpServletRequest request) {
        String token = (String) request.getSession().getAttribute(TokenInterceptor.TOKEN);
        if (token.endsWith("6") || token.endsWith("3") || token.endsWith("9")) {
            throw new RuntimeException("发生异常");
        }
        return "detail";
    }

    @GetMapping(value = "/submit")
    @Token(remove = true)
    public String goSubmit() {
        return "submit";
    }

}
